package com.vueblog.webapi.controller;


import com.vueblog.webapi.enums.ResponseEnum;
import com.vueblog.webapi.response.BaseResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpSession;


/**
 * @author lsj
 * @create 2021-05-16 0:45
 */
@Controller
@RequestMapping("/test")
public class TestController{

    @GetMapping("/type")
    public String getType(){
        return "redirect:/admin/types.html";
    }

    @GetMapping("/html02")
    public String getHTML02(HttpSession session, RedirectAttributes attributes){
        session.setAttribute("lsj", "lsj");
//        attributes.addAttribute("user", "zhangsan");
        return "redirect:/admin/login.html";
    }

    @GetMapping("/html03")
    public String getHTML03(HttpSession session){
        System.out.println("进来了");
        session.setAttribute("name", "lsj");



//        Object attribute = request.getServletContext().getAttribute("loginCookie");
//        //获取当前会话的所有的Cookie对象
//        Cookie[] cookies = request.getCookies();
//        if(cookies != null) {
//            // 遍历cookie
//            for (Cookie cookie : cookies) {
//                if ("JSESSIONID".equals(cookie.getName())) {
//                    // 获取键为JSESSIONID的cookie值
//                    String jsessionId = cookie.getValue();
//                    if (attribute != null) {
//                        // 强转为String类型
//                        String loginCookie = (String) attribute;
//                        if (jsessionId.equals(loginCookie)) {
//                            // 如果键为JSESSIONID的cookie值 与 上下文中键为loginCookie的属性值相等，那么就表示是同一个会话
//                            return new BaseResponse(ResponseEnum.SUCCESS);
//                        }
//                    }
//                }
//            }
//        }
//        return new BaseResponse(ResponseEnum.ERROR);










        return "admin/login";
    }
}
